package com.dong.trues;

import java.util.Arrays;

/**
去掉最低的20个人和最高的20个人后计算全校学生平均身高。全校人数为n(> 1000),要求时间复杂度小于O(n^2)
 */
public class Demo1 {
    public static void main(String[] args) {
        double[] height = {1.72,1.5,1.65,1.8,1.68,1.56,1.68,};
    }

    public double average(double[] height){
        int n = height.length;
        double sum = 0;
        double[] arrays = new double[n - 40];
        Arrays.sort(height);
        for (int i = 20; i <= n-20; i++) {
            arrays[i-20] = height[i];
            sum = sum + height[i];
        }
        double average = sum/(n-40);
        return average;
    }
}
